package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CmsCategory;
import com.ruoyi.system.service.ICmsCategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/cms/category")
public class CmsCategoryController extends BaseController {

    @Resource
    private ICmsCategoryService cmsCategoryService;

    @GetMapping("/list")
    public TableDataInfo list(CmsCategory category) {
        startPage();
        List<CmsCategory> list = cmsCategoryService.selectCmsCategoryList(category);
        return getDataTable(list);
    }

    @GetMapping(value = "/{categoryId}")
    public AjaxResult getInfo(@PathVariable Long categoryId) {
        return AjaxResult.success(cmsCategoryService.selectCmsCategoryById(categoryId));
    }

    @Log(title = "资讯栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsCategory category) {
        return toAjax(cmsCategoryService.insertCmsCategory(category));
    }

    @Log(title = "资讯栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsCategory category) {
        return toAjax(cmsCategoryService.updateCmsCategory(category));
    }

    @Log(title = "资讯栏目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}")
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(cmsCategoryService.deleteCmsCategoryByIds(categoryIds));
    }
}


